<template>
	<view class="container">
		<view class="card">
			<view class="title">登录</view>

			<input class="input" placeholder="请输入用户名" v-model="username" />
			<input class="input" placeholder="请输入密码" v-model="password" password="true" />

			<button class="btn" @click="login">登录</button>

			<view class="footer">
				<text class="hint">没有账号？</text>
				<navigator url="/pages/register/register">
					<text class="link">去注册</text>
				</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "LoginPage",
		data() {
			return {
				username: "",
				password: ""
			};
		},
		methods: {
			login() {
				if (!this.username) {
					uni.showToast({
						title: "请输入用户名",
						icon: "none"
					});
					return;
				}
				if (!this.password) {
					uni.showToast({
						title: "请输入密码",
						icon: "none"
					});
					return;
				}

				// === 显示 Loading ===
				uni.showLoading({
					title: "登录中..."
				});
				

				
				
				// 模拟登录操作
				setTimeout(() => {
					uni.setStorage({
						key: 'Account',
						data: {
							nickname: this.username,
							avatar: ''
						},
						success: () => {

							// === 关闭 Loading ===
							uni.hideLoading();

							uni.showToast({
								title: "登录成功",
								icon: "success"
							});

							// 登录成功后切换到 TabBar 页面
							uni.switchTab({
								url: "/pages/tabBar/loginppage/loginppage"
							});
						}
					});
				}, 800); // 0.8秒模拟网络延迟
			}
		}
	};
</script>

<style scoped>
	.container {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100vh;
		background: #f5f5f5;
	}

	.card {
		width: 80%;
		padding: 40rpx 30rpx;
		background: #fff;
		border-radius: 12rpx;
		box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.12);
		text-align: center;
	}

	.title {
		font-size: 40rpx;
		font-weight: 600;
		margin-bottom: 30rpx;
		color: #333;
	}

	.input {
		width: 100%;
		height: 70rpx;
		margin-bottom: 22rpx;
		padding: 0 20rpx;
		border: 1rpx solid #ddd;
		border-radius: 8rpx;
		font-size: 28rpx;
		text-align: left;
		box-sizing: border-box;
	}

	.btn {
		width: 100%;
		height: 70rpx;
		line-height: 70rpx;
		background: #5A9977;
		color: #fff;
		font-size: 30rpx;
		border-radius: 8rpx;
		margin-top: 10rpx;
	}

	.footer {
		margin-top: 25rpx;
		display: flex;
		justify-content: center;
		font-size: 24rpx;
	}

	.hint {
		color: #666;
	}

	.link {
		margin-left: 8rpx;
		color: #5A9977;
	}
</style>
